﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using RedDragon.Common.Dtos;
using RedDragon.RBAC.API.Application.Common.Permission;
using T.Common.Domain.Common;

namespace RedDragon.RBAC.API.Controllers
{
    /// <summary>
    /// 权限管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class PermissionsController : ControllerBase
    {
        private readonly IMediator mediator;

        public PermissionsController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 权限管理添加
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> AddCondition(CreatePermissionsCommand cmd)
        {
            return await mediator.Send(cmd);
        }

        /// <summary>
        /// 获取权限列表
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result<PageResultDto<PermissionsDto>>> QueryCondition(QueryPermissionsCommand cmd)
        {
            return await mediator.Send(cmd);
        }

        /// <summary>
        /// 权限管理分类列表
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> GetPermissionTypes(GetPermissionTypesCommand cmd)
        {
            return await mediator.Send(cmd);
        }

        /// <summary>
        /// 权限删除
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<Result> DeletePermission(DeletePermissionCommand cmd)
        {
            return await mediator.Send(cmd);
        }
        /// <summary>
        /// 无条件权限列表
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> SearchPermission(SearchPermissionCommand cmd)
        {
            return await mediator.Send(cmd);
        }

        /// <summary>
        /// 根据权限id获取信息
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> FanPermission(FanPermissionCommand cmd)
        {
            return await mediator.Send(cmd);
        }

        /// <summary>
        /// 权限修改
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<Result> UpdatePermissions(UpdatePermissionsCommand cmd)
        {
            return await mediator.Send(cmd);
        }
    }
}
